var mongoose = require('mongoose');

var Schema = mongoose.Schema;

var schema = new Schema({
  related_id: String,
  type:String,
  addid:String,
  diaryid:String,
  created_at:Date
});

schema.set('collection','tips');

var tips = mongoose.model('tips',schema);

tips.statics.addDiaryTips = function(userid,diaryid){
  new tips({
    related_id:userid,
    type:'diary',
    diaryid:diaryid
  }).save().then();
};

tips.statics.removeDiaryTips = function(userid,diaryid){
  this.find({
    related_id: userid,
    diaryid: diaryid,
    type: 'diary'
  }).save().then();
};

tips.statics.addFriendsTips = function(userid,addid){
  new tips({
    related_id: userid,
    type: 'friend',
    addid:addid
  }).save().then();
};

tips.statics.removeFriendsTips = function(userid,addid){
  this.find({
    related_id: userid,
    addid: addid,
    type: 'friend'
  }).save().then();
};

module.exports = tips;
